import { createStore } from 'vuex'

const store = createStore({
  // 定义全局状态
  state() {
    return {
      loginStatus: sessionStorage.getItem('loginStatus') || '',
    }
  },
  actions: {},
  // 在mutations中修改全局状态
  mutations: {
    SAVE_LOGIN_STATUS(state, status: string) {
      // 给路由守卫使用
      state.loginStatus = status
      sessionStorage.setItem('loginStatus', status)
    }
  },
  getters: {}
})

export default store